<?php
/**
 * 
 * Enter description : Thao tác thư nháp
 * @author admin888
 *
 */
class Model_thunhap extends Zend_Db_Table
{
	protected $_db = 'null';
	protected $_tn = 'thu_gui';
	protected $_dk = 'dinh_kem';
	public function __construct()
	{
	  $this->_db =  Zend_Registry::get('connectDb');
	}
	/**
	 * admin888 <doan.hut@gmail.com>
	 * Enter description : get thu nhap 
	 * @param unknown_type $idthunhap
	 */
	public function  getthunhap($idthunhap)
	{
	  $sql = $this->_db->select()
	  				   ->from($this->_tn)
	  				   ->where('id_tg ='.$idthunhap);
	  return  $this->_db->fetchRow($sql);				   
	  				   	
	}
	/**
	 * admin888 <doan.hut@gmail.com>
	 * Enter description here ...
	 * @param unknown_type $idthunhap
	 */
	public function getfiletheothu($idthunhap)
	{
		 $sql = $this->_db->select()
		 				  ->from($this->_dk)
		 				  ->where('id_t ='.$idthunhap);
		return  $query = $this->_db->fetchAll($sql);				  	
	}
	/**
	 * get file 
	 * Enter description here ...
	 * @param unknown_type $idfile
	 */
	public function getfile($idfile)
	{
		$sql = $this->_db->select()
						 ->from($this->_dk)
						 ->where('dk_id ='.$idfile);
	return  $this->_db->fetchRow($sql);					 	
	}
	/**
	 * xoa file trong db
	 * Enter description here ...
	 * @param unknown_type $idfile
	 */
	public function xoafiletrongdb($idfile)
	{
		$where = 'dk_id ='.$idfile;
		$this->_db->delete($this->_dk,$where);
	}
	/**
	 * admin888 <doan.hut@gmail.com>
	 * Enter description : them filecho thu nhap
	 * @param unknown_type $data
	 */
	public function addfilethunhap($data,$uid)
	{
		$mang = array(
				'link_file'  =>$data['hinh'],
				'loai_thu'   =>0,
				'id_t'		 =>$data['idthunhap'],
				'uid'		 =>$uid
		);
	  $this->_db->insert($this->_dk,$mang);
	 $idins = $this->_db->lastInsertId($this->_dk,'dk_id');
	return  $idins; 	
	}
	/**
	 * admin888 <doan.hut@gmail.com>
	 * Enter description : update lai tonh file
	 * @param unknown_type $sofile
	 */
	public function demlaisofile($sofile,$idt)
	{
		$arr = array(
			'tong_files'  =>$sofile,
		);
		$where = "id_tg =".$idt;
	$this->_db->update($this->_tn, $arr ,$where);	
		
	}
	/**
	 * admin888 <doan.hut@gmail.com>
	 * Enter description : updatethunhap
	 * @param unknown_type $data
	 */
	public function updatethunhap($uid,$data)
	{
		   $date=  date('d-m-Y H:i:s');	
		   $arr = array(
				
				'id_lh'				=>$data['arr_idlh'],
				'email_nguoinhan'	=>$data['arr_email'],
				'show_nguoinhan'	=>stripslashes($data['show_nguoinhan']),
				'cc_email'			=>$data['cc_'],
				'bcc_email'			=>$data['bcc_'],	
				'tieu_de'			=>$data['chu_de'],	
				'tk_id'  			=>$data['idtukhoa'],	
				'noi_nung'			=>stripslashes($data['noidung_thu_soan']),	
				'ngay_sua'		    =>$date	
			);
			$where = "id_tg =".$data['idthunhap'];
	  return 	$this->_db->update($this->_tn, $arr,$where);			
	}
	/**
	 * admin888 <doan.hut@gmail.com>
	 * Enter description : update tu thu nhap qua thu da gui
	 * @param unknown_type $uid
	 * @param unknown_type $data
	 */
	public function chuyenthunhapquadagui($uid,$data)
	{
			$date=  date('d-m-Y H:i:s');	
		   $arr = array(
				
				'id_lh'				=>$data['arr_idlh'],
				'email_nguoinhan'	=>$data['arr_email'],
				'show_nguoinhan'	=>stripslashes($data['show_nguoinhan']),
				'cc_email'			=>$data['cc_'],
				'bcc_email'			=>$data['bcc_'],	
				'tieu_de'			=>$data['chu_de'],	
				'tk_id'  			=>$data['idtukhoa'],	
				'noi_nung'			=>stripslashes($data['noidung_thu_soan']),	
				'ngay_sua'		    =>$date,	
				'da_gui'		    =>1	
			);
			$where = "id_tg =".$data['idthunhap'];
	  return 	$this->_db->update($this->_tn, $arr,$where);
	}
	/**
	 * admin888 <doan.hut@gmailcom>
	 * Enter description : update file 
	 * @param unknown_type $data
	 */
	public function udateloaifile($uid,$data)
	{
		$arr = array(
			'loai_thu'  		=>1
		);
		$where = "id_t =".$data['idthunhap'];
	 	return  $this->_db->update($this->_dk, $arr,$where);
	}
}